package org.wk.user.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.wk.core.common.view.PageVo;
import org.wk.core.common.view.ResponseVo;
import org.wk.user.domain.ApplyVip;
import org.wk.user.enums.VerifyStatus;
import org.wk.user.service.ApplyVipService;
import org.wk.user.view.ApplyVipVo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ApplyVipController
 * @Description 用户VIP申请
 * @Author ZhaoPing'an
 * @Date 2018/6/1 10:46
 */
@RestController
@RequestMapping("/users/applyvip")
public class ApplyVipController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private  ApplyVipService applyVipService;

    /**
     * @Description VIP申请 列表
     * @Param [params]
     * @author ZhaoPing'an
     * @Date 2018/6/1 15:44
     */
    @RequestMapping("/list")
    public ResponseVo list(@RequestParam Map<String, Object> params){
        PageVo page = applyVipService.findApplyVipListPage(params);
        return ResponseVo.success().addAttribute("page",page);
    }

    /**
     * @Description 获取申请详细信息
     * @Param [applyId]
     * @author ZhaoPing'an
     * @Date 2018/6/2 11:13
     */
    @RequestMapping("/info/{id}")
    public ResponseVo applyVipInfo(@PathVariable("id")String id){
        ApplyVipVo applyInfo = applyVipService.findApplyVipInfo(id);
        return ResponseVo.success().setData(applyInfo);
    }

    /**
     * @Description VIP申请初审通过
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/2 17:14
     */
    @RequestMapping("/firstVerify/{id}")
    public ResponseVo firstVerify(@PathVariable("id")String id){
        applyVipService.firstVerify(id);
        return ResponseVo.success();
    }

    /**
     * @Description 初审不通过
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/4 9:19
     */
    @RequestMapping("/refuseFirstVerify")
    public ResponseVo refuseFirstCheck(@RequestBody ApplyVipVo applyVip){
        applyVipService.refuseFirstVerify(applyVip);
        return ResponseVo.success();
    }

    /**
     * @Description VIP申请终审通过
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/4 9:20
     */
    @RequestMapping("/finalVerify/{id}")
    public ResponseVo finalVerify(@PathVariable("id")String id){
        ResponseVo result = applyVipService.finalVerify(id);
        return result;
    }

    /**
     * @Description 终审不通过
     * @Param [id]
     * @author ZhaoPing'an
     * @Date 2018/6/4 12:16
     */
    @RequestMapping("/refuseFinalVerify")
    public ResponseVo refuseFinalVerify(@RequestBody ApplyVip applyVip){
        applyVipService.refuseFinalVerify(applyVip);
        return ResponseVo.success();
    }

    /*
     * @description 获取VIP申请状态集合
     * @param
     * @author ZhaoPing'an
     * @date 2018/8/16 14:57
     */
    @RequestMapping("/getApplyStatus")
    public ResponseVo getApplyStatus(){
        VerifyStatus.values();
        List<Map<String,String >> result = new ArrayList<>();
        for (VerifyStatus temp:VerifyStatus.values()){
            Map<String,String > applyStatus = new HashMap<>();
            applyStatus.put("code",temp.getCode());
            applyStatus.put("name",temp.getName());
            result.add(applyStatus);
        }
        return ResponseVo.success().setData(result);
    }

}
